package com.ruoyi.office.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.office.domain.Personal;
import com.ruoyi.office.service.IPersonalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工个人信息Controller
 * 
 * @author lidelong
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/office/personal")
public class PersonalController extends BaseController
{
    @Autowired
    private IPersonalService personalService;

    /**
     * 查询员工个人信息列表
     */
    @PreAuthorize("@ss.hasPermi('office:personal:list')")
    @GetMapping("/list")
    public TableDataInfo list(Personal personal)
    {
        startPage();
        List<Personal> list = personalService.selectPersonalList(personal);
        return getDataTable(list);
    }

    /**
     * 导出员工个人信息列表
     */
    @PreAuthorize("@ss.hasPermi('office:personal:export')")
    @Log(title = "员工个人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Personal personal)
    {
        List<Personal> list = personalService.selectPersonalList(personal);
        ExcelUtil<Personal> util = new ExcelUtil<Personal>(Personal.class);
        util.exportExcel(response, list, "员工个人信息数据");
    }

    /**
     * 获取员工个人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('office:personal:query')")
    @GetMapping(value = "/{personalId}")
    public AjaxResult getInfo(@PathVariable("personalId") Long personalId)
    {
        return success(personalService.selectPersonalByPersonalId(personalId));
    }

    /**
     * 新增员工个人信息
     */
    @PreAuthorize("@ss.hasPermi('office:personal:add')")
    @Log(title = "员工个人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Personal personal)
    {
        return toAjax(personalService.insertPersonal(personal));
    }

    /**
     * 修改员工个人信息
     */
    @PreAuthorize("@ss.hasPermi('office:personal:edit')")
    @Log(title = "员工个人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Personal personal)
    {
        return toAjax(personalService.updatePersonal(personal));
    }

    /**
     * 删除员工个人信息
     */
    @PreAuthorize("@ss.hasPermi('office:personal:remove')")
    @Log(title = "员工个人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{personalIds}")
    public AjaxResult remove(@PathVariable Long[] personalIds)
    {
        return toAjax(personalService.deletePersonalByPersonalIds(personalIds));
    }
}
